import 'package:flutter/material.dart';
// import 'package:my_app/003--%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E9%A1%B9%E7%9B%AE%E6%90%AD%E5%BB%BA/%E5%A4%87%E8%AF%BE%E4%BB%A3%E7%A0%81/flutter_app/lib/state_mag_demo.dart';
import 'Home.dart';
import '002-第二节--Flutter布局&状态管理课程资料/layout_demo.dart';
import '002-第二节--Flutter布局&状态管理课程资料/base_widget.dart';
import '002-第二节--Flutter布局&状态管理课程资料/listview_demo.dart';
import '003--项目实战-项目搭建/state_mag_demo.dart';
import '003--项目实战-项目搭建/wechat_demo03/root_page.dart';
import '007--网络&多线程/007_asynetwork.dart';
import '008--网络&项目实战/008dio.dart';
import '010--Flutter生命周期&渲染原理/010life.dart';
import '011--混合开发下&插件开发/011main.dart';

void main() {
  runApp(flutterApp());
}

final List<String> demoDatas =['layout_demoHome02','base_widgetTextDemo',
  'state_mag_demo','MyApp003wechat','007_asynetwork','008_dio',
  '010--Flutter生命周期&渲染原理','011--混合开发下&插件开发'];
class SampleAppPage extends StatefulWidget {
  SampleAppPage({Key key}) : super(key: key);

  @override
  _SampleAppPageState createState() => _SampleAppPageState();
}

class _SampleAppPageState extends State<SampleAppPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Sample App"),
      ),
      body: ListView(children: _getListData()),
    );
  }

  _getListData() {
    List<Widget> widgets = [];
    for (int i = 0; i < demoDatas.length; i++) {
      widgets.add(GestureDetector(
        child: Padding(
          padding: EdgeInsets.all(10.0),
          child: Text(demoDatas[i]),
        ),
        onTap: () {
          print('name:'+demoDatas[i]+'index:'+'$i');
          // print(demoDatas[i]);
          // print(i);
          // switch(i){
          //   case 0:
              Navigator.of(context).pushNamed('$i');//路由跳转
              // break;
          // }
        },
      ));
    }
    return widgets;
  }
}
class flutterList extends StatelessWidget {
  Widget _itemForRow(BuildContext context, int index) {
    return Container(
        child: Column(
          children: <Widget>[
            SizedBox(height: 10),//换行占位
            Text(
              demoDatas[index],
              style: TextStyle(
                fontWeight: FontWeight.w800,
                fontSize: 18.0,
                fontStyle: FontStyle.values[1],
              ),
            ),
          ],
        ));
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: demoDatas.length,
      itemBuilder: _itemForRow,//渲染
    );
  }
}

class flutterHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'flutter_demo',
      theme: ThemeData(//主题
        primaryColor: Colors.white,
      ),
      home:SampleAppPage(),
      // home: Scaffold(
      //   appBar: AppBar(title: Text('flutter_demo'),),
      //    body: flutterList(),
      // ),
      //路由 定义
      routes: <String,WidgetBuilder>{
        '0': (BuildContext context) => layout_demoHome02(),
        '1': (BuildContext context) => base_widgetTextDemo(),
        '2': (BuildContext context) => MyApp03state_mag_demo(),
        '3': (BuildContext context) => MyApp003wechat(),
        '4': (BuildContext context) => dioDemo007(),
        '5': (BuildContext context) => dioDemo008(),
        '6': (BuildContext context) => MyApp010(),
        '7': (BuildContext context) => MyApp011(),
      },
    );
  }
}

class flutterApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return flutterHome();
    return base_widgetTextDemo();
    return MaterialApp(
      title: 'demo',
      home: Scaffold(
        appBar: AppBar(title: Text('flutter demo'),),
        body: flutterHome(),
      ),
    );

    return base_widgetTextDemo();
    return layout_demoHome02();
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: layout_demoHome02(),
      // home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
